package com.cy.sys.exception;

import org.apache.shiro.ShiroException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cy.sys.log.page.vo.JSONResult;

@ControllerAdvice
public class HanderException {
	 	@ExceptionHandler(ShiroException.class) 
	    @ResponseBody
		public JSONResult doHandleShiroException(ShiroException e) {
		 	JSONResult r=new JSONResult(); 	
			r.setState(0);
			if(e instanceof UnknownAccountException) {
				r.setMessage("账户不存在");
			}else if(e instanceof LockedAccountException) {
				r.setMessage("账户已被禁用");
			}else if(e instanceof IncorrectCredentialsException) {
				r.setMessage("密码不正确");
			}else if(e instanceof AuthorizationException) {
				r.setMessage("没有此操作权限");
			}else {
				r.setMessage("系统维护中");
			}
			e.printStackTrace();
			return r;
		}

	
	@ResponseBody
	@ExceptionHandler(RuntimeException.class)
	public JSONResult syshanderexception(RuntimeException e) {
		return new JSONResult(e);
	}
}
